package com.unittec.drainage.provider.utils;

import java.util.Date;
import java.util.Random;

/**
 * @Description:
 * @author: chenjiawang
 * @CreateDate: 2020/3/18 17:19
 */
public class BusinessCodeUtils {

    /**
     *
     */
    private static final String DEVICE_KEY = "SB";

    /**
     *
     */
    private static final String INSPECTION_PLAN_KEY = "XJJH";
    /**
     *
     */
    private static final String INSPECTION_TASK_KEY = "XJRW";
    /**
     *
     */
    private static final String REGION_KEY = "JKQY";
    /**
     *
     */
    private static final String CAMERA_KEY = "CA";
    /**
     *
     */
    private static final String DATE_FORMAT = "yyyyMMddHHmmssSSS";
    /**
     *
     */
    private static final String DATE_FORMAT_DATE = "yyyyMMddHHmmss";

    /**
     *
     */
    private static final String BASE_KEY = "QAZWSXEDCRFVTGBYHNUJMIKLOP0123456789";

    /**
     * 随机数
     *
     * @param place
     *            定义随机数的位数
     */
    private static String randomGen(int place) {
        StringBuilder sb = new StringBuilder();
        Random rd = new Random();
        for (int i = 0; i < place; i++) {
            sb.append(BASE_KEY.charAt(rd.nextInt(BASE_KEY.length())));
        }
        return sb.toString();
    }

    /**
     * @return
     */
    public static String getDeviceCode() {
        String sb = DEVICE_KEY + DateUtils.format(new Date(), DATE_FORMAT) + randomGen(5);
        return sb.toUpperCase();
    }

    /**
     * @return
     */
    public static String getInspectionPlanCode() {
        return (INSPECTION_PLAN_KEY + DateUtils.format(new Date(), DATE_FORMAT) + randomGen(5)).toUpperCase();
    }

    /**
     * @return
     */
    public static String getInspectionTaskCode() {
        return (INSPECTION_TASK_KEY + DateUtils.format(new Date(), DATE_FORMAT) + randomGen(5)).toUpperCase();
    }

    /**
     * @return
     */
    public static String getRegionCode() {
        return (REGION_KEY + DateUtils.format(new Date(), DATE_FORMAT) + randomGen(5)).toUpperCase();
    }

    /**
     * @return
     */
    public static String getCameraCode() {
        return (CAMERA_KEY + DateUtils.format(new Date(), DATE_FORMAT) + randomGen(5)).toUpperCase();
    }
}
